#!/bin/bash

service_type=${SERVICE_TYPE}    #服务类型  [api|crawl]
instance_id=${INSTANCE_ID}		#实例ID		0,1,2...,不能重复

work_base="/data/hms"

#设置服务名称、服务描述、执行程序
#服务类型 api|crawl
case "${service_type}" in
"api")
    service_name="hms_${service_type}_${instance_id}"
    work_dir="${work_base}/hms_${service_type}_${instance_id}"
;;
"service")
    service_name="hms_as_${service_type}_${instance_id}"
    work_dir="${work_base}/hms_as_${service_type}_${instance_id}"
;;
*)
echo "hms uninstall error with invalid service_type[${service_type}] "
exit
;;
esac

#清除多余字符串
service_name=$(echo -n ${service_name} | tr '[A-Z]' '[a-z]')

#停止服务
systemctl stop ${service_name}
systemctl disable ${service_name}

#删除服务文件
hms_service="/etc/systemd/system/${service_name}.service"
hms_service=$(echo -n ${file_service} | tr '[A-Z]' '[a-z]')
rm -rf ${file_service}

#删除工作目录
work_dir=$(echo -n ${work_dir} | tr '[A-Z]' '[a-z]')
rm -rf ${work_dir}
